package top.eleven.sixpence.generaterollbacksql.processor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.eleven.sixpence.generaterollbacksql.annotation.Value;
import top.eleven.sixpence.generaterollbacksql.holder.PropertiesHolder;

/**
 * 将相关配置提取到配置文件中，通过配置文件管理
 *
 * @author Eleven
 */
public class ProcessorProperties {
    private static final Logger LOGGER = LoggerFactory.getLogger(ProcessorProperties.class);
    /*文件输出地址*/
    private String outputFilePath;
    /*成功转换sql文件名*/
    private String outputFileName;
    /*失败转换sql文件名*/
    private String convertFailedSqlFile;
    /*需要手动备份数据的sql文件名*/
    private String needBackupDataManual;
    /**
     * 需要人工确认的sql文件名
     */
    private String needConfirmSqlFile;
    /**
     *  单行注释标识，用于排除注释行，按需配置，
     *  尽量只配置项目sql中使用的注释类型，配置多余项会导致降低性能
     */
    private String[] singleAnnotator;
    /**
     * 多行注释开始标识
     */
    private String multilineAnnotatorPre;
    /**
     * 多行注释结束标识
     */
    private String multilineAnnotatorSuf;
    /**
     * 解析插入sql转换为删除sql时，若插入sql中的值存在于该配置中
     * 生成的删除sql不再作为条件
     */
    private String[] ignoreValues;

    private void init(){
        PropertiesHolder.setProperties(this);
    }

    public String getOutputFilePath() {
        return outputFilePath;
    }

    @Value(key = "rollback.sql.outputFilePath", defaultValue = "/home/rollbackSql")
    public void setOutputFilePath(String outputFilePath) {
        this.outputFilePath = outputFilePath;
    }

    public String getOutputFileName() {
        return outputFileName;
    }

    @Value(key = "rollback.sql.outputFileName", defaultValue = "rollback-sql.sql")
    public void setOutputFileName(String outputFileName) {
        this.outputFileName = outputFileName;
    }

    public String getConvertFailedSqlFile() {
        return convertFailedSqlFile;
    }

    @Value(key = "rollback.sql.convertFailedSqlFile", defaultValue = "convert-failed.sql")
    public void setConvertFailedSqlFile(String convertFailedSqlFile) {
        this.convertFailedSqlFile = convertFailedSqlFile;
    }

    public String getNeedBackupDataManual() {
        return needBackupDataManual;
    }

    @Value(key = "rollback.sql.needBackupDataManual", defaultValue = "need-backup-data-manual.sql")
    public void setNeedBackupDataManual(String needBackupDataManual) {
        this.needBackupDataManual = needBackupDataManual;
    }

    public String getNeedConfirmSqlFile() {
        return needConfirmSqlFile;
    }

    @Value(key = "rollback.sql.needConfirmSqlFile", defaultValue = "need-confirm.sql")
    public void setNeedConfirmSqlFile(String needConfirmSqlFile) {
        this.needConfirmSqlFile = needConfirmSqlFile;
    }

    public String[] getSingleAnnotator() {
        return singleAnnotator;
    }

    @Value(key = "rollback.sql.singleAnnotator", defaultValue = "--,#,//,comment,COMMENT")
    public void setSingleAnnotator(String[] singleAnnotator) {
        this.singleAnnotator = singleAnnotator;
    }

    public String getMultilineAnnotatorPre() {
        return multilineAnnotatorPre;
    }

    @Value(key = "rollback.sql.multilineAnnotatorPre", defaultValue = "/*")
    public void setMultilineAnnotatorPre(String multilineAnnotatorPre) {
        this.multilineAnnotatorPre = multilineAnnotatorPre;
    }

    public String getMultilineAnnotatorSuf() {
        return multilineAnnotatorSuf;
    }

    @Value(key = "rollback.sql.multilineAnnotatorSuf", defaultValue = "*/")
    public void setMultilineAnnotatorSuf(String multilineAnnotatorSuf) {
        this.multilineAnnotatorSuf = multilineAnnotatorSuf;
    }

    public String[] getIgnoreValues() {
        return ignoreValues;
    }

    @Value(key = "rollback.sql.ignoreValues", defaultValue = "NULL,null,sysdate")
    public void setIgnoreValues(String[] ignoreValues) {
        this.ignoreValues = ignoreValues;
    }

    private ProcessorProperties() {
        init();
    }

    public static ProcessorProperties build(){
        return ProcessorPropertiesFactroy.NEW_INSTANCE;
    }

    private static final class ProcessorPropertiesFactroy {
        private static final ProcessorProperties NEW_INSTANCE = new ProcessorProperties();
    }

}
